var t = require("../../../api.js"), e = getApp();

require("../../../utils/function.js");

Page({
    data: {
        isAll: !1,
        list: [],
        totalPrice: 0,
        page: 1
    },
    onLoad: function(t) {},
    invoice: function() {
        if (0 == this.data.totalPrice) return wx.showToast({
            title: "请选择需要开发票的订单",
            icon: "none"
        }), !1;
        wx.navigateTo({
            url: "/pages/invoice/invoice/invoice"
        });
    },
    toDetail: function(t) {
        var e = t.currentTarget.dataset.url;
        wx.navigateTo({
            url: e
        });
    },
    getList: function() {
        var i = this;
        e.request({
            url: t.order.order_list,
            method: "post",
            data: {
                is_pay: 1,
                is_invoice: 0,
                type: 5,
                p: 10,
                page: i.data.page
            },
            success: function(t) {
                if (1 == t.code) {
                    var e = t.data.data;
                    if (0 == e.length) return wx.showToast({
                        title: "没有更多数据了",
                        icon: "none"
                    }), !1;
                    0 != e.length && 1 != i.data.page && i.setData({
                        isAll: !1
                    });
                    var a = i.data.list;
                    e.forEach(function(t, e) {
                        t.selected = !1;
                    }), e = a.concat(e), i.setData({
                        list: e,
                        total: t.data.total
                    });
                }
            }
        });
    },
    onReachBottom: function() {
        console.log("触底了"), this.data.page++, this.getList();
    },
    singleSelect: function(t) {
        var e = this, i = t.currentTarget.dataset.idx, a = this.data.list;
        a[i].selected = !a[i].selected, this.setData({
            list: a
        }, function() {
            e.isSelectAll(), e.getPrice();
        });
    },
    isSelectAll: function() {
        for (var t = this.data.list, e = 0, i = 0; i < t.length; i++) t[i].selected && e++;
        this.setData({
            isAll: e == t.length
        });
    },
    selectAll: function() {
        var t = !this.data.isAll, e = this, i = e.data.list;
        i.forEach(function(e, i) {
            e.selected = t;
        }), this.setData({
            isAll: t,
            list: i
        }, function() {
            e.getPrice();
        });
    },
    getPrice: function() {
        for (var t = 0, e = "", i = this.data.list, a = 0; a < i.length; a++) i[a].selected && (t += Number(i[a].pay_price), 
        e += i[a].order_no + ",");
        var n = {
            price: t.toFixed(2),
            orderLists: e
        };
        wx.setStorageSync("INVOICE_DETAIL", n), this.setData({
            totalPrice: t.toFixed(2)
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = this;
        this.setData({
            list: []
        }, function() {
            t.getList(), t.getPrice(), t.isSelectAll();
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onShareAppMessage: function() {}
});